<%@page import="com.netistate.pojo.LaborStat"%>
<%@page import="com.netistate.pojo.Labor"%>
<%@page import="com.netistate.pojo.User"%>
<%@page import="com.netistate.pojo.Project"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<%
  List<User> userList = (List<User>)request.getSession().getAttribute("userList");
/*
  LaborAction laborAction=new LaborAction();
  List<Labor> list1=new ArrayList<Labor>();
  List<Labor> list = (List<Labor>)request.getSession().getAttribute("list");
  if(list == null){
     list1 = laborAction.searchAllLaborByTime();
  }else{
     list1 = list;
  }
  //对list1里的Labor进行排序
  List<Labor> list2=new ArrayList<Labor>();
  list2 = SequenceByTime.sequenceByLabor(list1); */
  
  List<Project> listQuery = (List<Project>)request.getSession().getAttribute("projectList");
%>
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/common.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/table.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/trash.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/labor/labor.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/calendar/Calendar.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
	<script type="text/javascript" >
	  function add(){
	     PigossMsg.show("${pageContext.request.contextPath}/jsp/labor/addLabor.jsp","添加工时",400,390,"AddLabor.saveConfig()");
	  }
	  function delLabor(id,msg){
	        this.msg = msg;
	        PigossMsg.confirm(this.msg,null,function yesHandler(){EditLabor.del(id)},function noHandler(){});
	  
	   };
	   function isValid(){
	       var  dayStart=document.getElementById("dayStart").value;
	       var  dayEnd=document.getElementById("dayEnd").value;
	       if(dayStart!="7天前" && dayEnd!="现在"){
	           dayStart=dayStart.split("-");
		       dayEnd=dayEnd.split("-");
		       var timeStart=new Date(dayStart[0],dayStart[1],dayStart[2]);
		       var timeEnd=new Date(dayEnd[0],dayEnd[1],dayEnd[2]);
		       if(timeStart>=timeEnd){
		          PigossMsg.alert("开始时间必须小于结束时间！");
		          return false;
		       }
	       }
	   }
	   //显示工时查询下拉
	   function showLaborQuery(){
	   		var idDiv = document.getElementById('query_labor_condition');
	   		var stat = document.getElementById('query_stat');
	   		
	        if(idDiv.style.display=='none'){
	            idDiv.style.display='block'; 
	            stat.style.display='none';
	        }else{
	           idDiv.style.display='none'; 
	        };
	        
	   };
	   //显示工时统计下拉
	   function showLaborStat(){
	   		var stat = document.getElementById('query_stat');
	   		var idDiv = document.getElementById('query_labor_condition');
	   		
	   		AjaxUtil.request({
				url : 'show_labor_stat.action',
				params : {},
				success : function(responseText){
   					
				},
				failure : function(){
					PigossMsg.alert("修改失败!");
				}
			});
			if(stat.style.display=='none'){
	            stat.style.display='block'; 
	            idDiv.style.display='none'; 
	        }else{
	           stat.style.display='none'; 
	        };
	        /* if(stat.style.display=='none'){
	            stat.style.display='block'; 
	            idDiv.style.display='none'; 
	        }else{
	           stat.style.display='none'; 
	        }; */
	   };
	   //显示工时统计下拉下面的按阶段查询
	   function showState(){
	   		var content = document.getElementById('condition_query_by_content');
	   		var state = document.getElementById('condition_query_by_statues');
	        if(state.style.display=='none'){
	            state.style.display='block'; 
	            content.style.display='none'; 
	        }else{
	           content.style.display='none'; 
	        };
	   	
	   };
	   //显示工时统计下拉下面的按内容查询
	   function showContent(){
	   		var content = document.getElementById('condition_query_by_content');
	   		var state = document.getElementById('condition_query_by_statues');
	        if(content.style.display=='none'){
	            content.style.display='block'; 
	            state.style.display='none';
	        }else{
	           state.style.display='none'; 
	        };
	   };
	   
	   //切换工时统计
	   function lookLabor(){
   			AjaxUtil.request({
				url : 'look_labor.action',
				params : {},
				success : function(responseText){
   					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/labor/labor.jsp";
				},
				failure : function(){
				}
			});
   		};
 
 		
 		//提交根据内容查询工时统计
 		function queryAllLSBySection(){
 			var countHours = document.getElementById("sectionHours").value;
 			var countPerson = document.getElementById("sectionPerson").value;
 			var query_AllLaborStatBySection = document.getElementById("query_AllLaborStatBySection");
 			var part = /^[1-9]d*$/;
 			if(!(part.test(countHours) || countHours == null || countHours == '')){
 				PigossMsg.alert("小时数必须为正整数！");
 				return;
 			};
 			if(!(part.test(countPerson) || countPerson == null || countPerson == '')){
 				PigossMsg.alert("人数必须为正整数！");
 				return;
 			};
 			
 			query_AllLaborStatBySection.action = "query_AllLaborStatBySection.action";
 			query_AllLaborStatBySection.submit();
 		};
 		
 		//导出
 		function exportExcel(){
	       var projectName=document.getElementById("addtechNoteProjectId").value;
	       var statues=document.getElementById("projectProcess").value;
	       var countHours2=document.getElementById("processHours").value;
	       var countPerson2=document.getElementById("processPerson").value;
	      if(countHours2!=""){
		       if(isNaN(countHours2)){
				    PigossMsg.alert("工时输入必须为数字！");
				    return false;
			} 
		   }
		   if(countPerson2!=""){
			      if(isNaN(countPerson2)){
					    PigossMsg.alert("现场人次输入必须为整数！");
					    return false;
				}
		   }
		   projectName=encodeURI(encodeURI(projectName));
		   statues=encodeURI(encodeURI(statues));
		   countHours2=encodeURI(encodeURI(countHours2));
		   countPerson2=encodeURI(encodeURI(countPerson2));  
	       var url = '${pageContext.request.contextPath}/jsp/labor/exportExcel.jsp?projectName='+projectName+'&statues='+statues+'&countHours2='+countHours2+'&countPerson2='+countPerson2;
	       var hint = '你确定要按阶段导出？';
	       PigossMsg.confirm(hint, null, function yesHandler() {
	              window.open(url);
	          });
	    }
	    //按内容导出
	    function exportExcelByContent(){
	       var projectName=document.getElementById("addtechNoteProjectId").value;
	       var content=document.getElementById("section").value;
	       var countHours=document.getElementById("sectionHours").value;
	       var countPerson=document.getElementById("sectionPerson").value;
	      if(countHours!=""){
		       if(isNaN(countHours)){
				    PigossMsg.alert("工时输入必须为数字！");
				    return false;
			} 
		   }
		   if(countPerson!=""){
			      if(isNaN(countPerson)){
					     PigossMsg.alert("现场人次输入必须为整数！");
					    return false;
				}
		   }
	       projectName=encodeURI(encodeURI(projectName));
		   content=encodeURI(encodeURI(content));
		   countHours=encodeURI(encodeURI(countHours));
		   countPerson=encodeURI(encodeURI(countPerson));  
	       var url = '${pageContext.request.contextPath}/jsp/labor/exportExcelByContent.jsp?projectName='+projectName+'&content='+content+'&countHours='+countHours+'&countPerson='+countPerson;
	       var hint = '你确定要按内容导出？';
	       PigossMsg.confirm(hint, null, function yesHandler() {
	              window.open(url);
	          });
	     
	    }
 	
	</script>

	</head>
	<body>
	
		<div id="xtab">
			<a id="rightDiv0_tab" href="#" class='homelink ' onclick="lookLabor()"><span style="cursor:pointer;">工时服务</span></a>
			<a id="rightDiv1_tab" href="#" class='homelink curren' onclick=""><span style="cursor: pointer;">工时统计</span></a>
		</div>
		<div id="query_stat" style="display:block">
			<div id="export_query" class="toolbar" >
				<a href="#" class='buttonlink txbtip' title='按工作内容统计查询' onclick="showContent()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/opera.png'/>按项目内容统计查询</a>
				<a href="#" class='buttonlink txbtip' title='按项目阶段统计查询' onclick="showState()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/safari.png'/>按项目阶段统计查询</a>
			</div>
			<div id="condition_query_by_content" class="toolbar" style="display:block;overflow-y:hidden;overflow-x:hidden">
				<form id="query_AllLaborStatBySection" name="form1" action=""  onSubmit=""  method="post">
					<table>
						<tr>
							<td class="td_title" width="30" title="项目名称"> 项目名称：</td>
							<td>
								<select id="addtechNoteProjectId" name="projectNameBySection" ;>
									<option title="所有" value="所有">所有</option>
									<%List<Project> projectList = (List<Project>)request.getSession().getAttribute("projectList");
									for(Project p : projectList){%>
									<option title="<%=p.getProjectName()%>" value="<%=p.getId() %>"><%=p.getProjectName()%></option>
									<% }%>
								</select>
							</td>
							<td class="td_title" width="30" title="工作内容">工作内容:</td>
							<td>
								<select id="section" name="section">
									<option value="所有">所有</option>
									<option value="研发" title="研发">研发</option>
									<option value="技术支持" title="技术支持">技术支持</option>
									<option value="交流" title="交流">交流</option>
									<option value="销售" title="销售">销售</option>
					            </select>
							</td>
							<td class="td_title" width="10" title="工时">工时：</td>
							<td class="td_title">
							      <input type="text" id="sectionHours" name="sectionHours" style="width:50;" />
							</td>
							<td class="td_title" width="30" title="现场人次">现场人次：</td>
							<td class="td_title" >
							       <input type="text" id="sectionPerson" name="sectionPerson" style="width:30" />
							</td>
							<td class="td_title">
							  <input type="button" style="width:40px;" onclick="queryAllLSBySection()" title="查询" value="查询" />
							</td>
							<td class="td_title">
							  <input type="button" title="按内容导出" style="width:80px;" value="按内容导出" onclick="exportExcelByContent()"/>
							</td>
							<td class="td_title">&nbsp;&nbsp;</td>
							<td class="td_title">&nbsp;&nbsp;</td>
						</tr>
					</table>
				</form>
		    </div>		
			<div id="condition_query_by_statues" class="toolbar" style="display:none;overflow-y:hidden;overflow-x:hidden">
				<form name="form2" action="query_AllLaborStatByProcess.action" onSubmit=""  method="post">
					<table>
						<tr>
							<td class="td_title" width="30" title="项目名称">项目名称：</td>
							<td width="70">
								<select id="addtechNoteProjectId" name="projectNameByProcess" ;>
									<option title="所有" value="所有">所有</option>
									<%for(Project p : projectList){%>
									<option title="<%=p.getProjectName()%>" value="<%=p.getId() %>"><%=p.getProjectName()%></option>
									<% }%>
								</select>
							</td>
							<td class="td_title" title="阶段">阶段:</td>
							<td>
								<select id="projectProcess" name="projectProcess">
									<option value="所有">所有</option>
						            <option value="售前">售前</option>
							  	 	<option value="已签单">已签单</option>
								   	<option value="实施">实施</option>
								   	<option value="已验收">已验收</option>
								   	<option value="停滞">停滞</option>
					            </select>
							</td>
							<td class="td_title" width="10" title="工时">工时：</td>
							<td class="td_title">
							      <input type="text" id="processHours" name="processHours" style="width:50;" />
							</td>
							
							<td class="td_title" width="30" title="现场人次">现场人次：</td>
							<td class="td_title" >
							       <input type="text" id="processPerson" name="processPerson" style="width:30" />
							</td>
							<td class="td_title">
							  <input type="button" style="width:40px;" title="查询" value="查询" />
							 </td>
							 <td class="td_title">
							  <input type="button" title="按阶段导出" style="width:80px;" value="按阶段导出" onclick="exportExcel()"/>
							 </td>
							<td class="td_title">&nbsp;&nbsp;</td>
							<td class="td_title">&nbsp;&nbsp;</td>
						</tr>
					</table>
				</form>
		    </div>
	    </div>
		<div id="show_labor_query" style="width:100%;height:95%; overflow-y:scroll; border:1px solid;" >
			<table id="dArticleList" width="100%" border="0" cellpadding="0" cellspacing="0"  class="resizable">
				<thead>
					<tr class="fixHead">
						<td class="td1" style="cursor:pointer" width="10%">项目名称</td>
						<td class="td1" style="cursor:pointer" width="15%">工时</td>
						<td class="td1" style="cursor:pointer" width="10%">阶段</td>
						<td class="td1" style="cursor:pointer" width="20%">工作内容</td>
						<td class="td1" style="cursor:pointer" width="10%">现场人次</td>
					</tr>
			    </thead>
				</tbody>
				<%
				List<LaborStat> list = new ArrayList<LaborStat>();
				List<LaborStat> lsList = (List<LaborStat>)request.getAttribute("twoList");
				if(lsList == null){
					list = (List<LaborStat>)request.getSession().getAttribute("laborStatList");
				}else{
					list = lsList;
				}
				for(LaborStat ls : list){
				%>
				<tr onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; " >  
		       		<td title="<%=ls.getProjectName() %>" align="center" class="td2 txbtip" ><%=ls.getProjectName() %></td>
		       		<td title="<%=ls.getWorkTime()%>" align="center" class="td2 txbtip" ><%=ls.getWorkTime() %></td>
		       		<td title="<%=ls.getProjectProcess() %>" align="center" class="td2 txbtip" ><%=ls.getProjectProcess() %></td>
		       		<td title="<%=ls.getSection() %>" align="center" class="td2 txbtip" ><%=ls.getSection() %></td>
		       		<td title="<%=ls.getCurrentPerson() %>" align="center" class="td2 txbtip" ><%=ls.getCurrentPerson() %></td>
				</tr>	
			  <%}%>	
					
				</tbody>
			</table>
		</div>
		<script type="text/javascript" >
		
		function editLabor(id){
			AjaxUtil.request({
				url : 'editLabor.action',
				params : {id:id},
				success : function(responseText){
					PigossMsg.show("${pageContext.request.contextPath}/jsp/labor/editLabor.jsp","修改工时",470,480,"EditLabor.editConfig()");
				},
				failure : function(){
					PigossMsg.alert("修改失败!");
				}
			});
		};
		initTableWidget('dArticleList',Array('S','S',"S",'S','S'));
			
			
		</script>
	</body>
</html>